import pandas

food_info = pandas.read_csv('food_info.csv')

calcium__mg_ = food_info['Calcium_(mg)']
print(calcium__mg_)
div_1000 = calcium__mg_ / 1000
print(div_1000)

# Adds 100 to each value in the column and return s Series object.
add_100 = calcium__mg_ + 100
print(add_100)

# Subtracts 100 from each value in the column and returns a Series object.
sub_100 = calcium__mg_ - 100
print(sub_100)

# Multiplies each value in the column
mul_2 = calcium__mg_ * 2
print(mul_2)

# It applies the arithmetic operator
# to the first value and the second in the both columns and so on
energ_kcal_ = food_info['Energ_Kcal']
water_energy = food_info['Water_(g)'] * energ_kcal_
print(water_energy)

# convert Iron_(mg) to Iron_(g)
iron_grams = food_info['Iron_(mg)'] / 1000
food_info['Iron_(g)'] = iron_grams
print(food_info['Iron_(g)'])

# Score = 2 * (Protein_(g)) -0.75 * (Lipid_Tot_(g))
protein__g_ = food_info['Protein_(g)']
weighted_protein = protein__g_ * 2
weighted_fat = food_info['Lipid_Tot_(g)']
initial_rating = weighted_protein + weighted_fat
print(initial_rating)

# the "Vit_A_IU" column ranges from 0 to 100000, while the "Fiber_TD_(g)" column ranges from 0 to 79
# For certain calculations, columns like "Vit_A_IU" can have a greater effect on the result,
# due to the scale of the values

# The largest value in the "Energ_Kcal" column
max_calories = energ_kcal_.max()
print(max_calories)

# normalized
normalized_calories = energ_kcal_ / max_calories
normalized_protein = protein__g_ / protein__g_.max()
food_info['Normalized_Calories'] = normalized_calories
food_info['Normalized_Protein'] = normalized_protein

print(food_info.columns.tolist())

# By default, pandas will sort the data by the column we specify in ascending order and return a new DataFrame
# Sorts the DataFrame in-place, rather than returning a new DataFrame.
# print food_info["Sodium_(mg)"]

# show result after sort
food_info.sort_values('Sodium_(mg)', inplace=True)
print(food_info.head())

# sorts by descending order, rather than ascending.
food_info.sort_values('Sodium_(mg)', inplace=True, ascending=False)
print(food_info.head())
print(food_info['Sodium_(mg)'])
